package org.example.attendancesystem.controller;

import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import java.net.URI;
import java.net.URISyntaxException;
import java.util.Map;

@RestController
public class GetController {
    @Resource
    private RestTemplate restTemplate;
    @Value("${ak}")
    private String ak;

    @GetMapping("/get")
    public Object getAddrByUserIP(HttpServletRequest request) throws URISyntaxException {
        String url = "https://api.map.baidu.com/location/coor=bd09ll&ak="+ak;
        //发送请求
        ResponseEntity<Map> forEntity = restTemplate.getForEntity(new URI(url), Map.class);
        Map result = forEntity.getBody();
        return result;
    }
}
